CISC 1110 Lab 25
For this lab, use the vet_record class
you wrote in Labs 23 and 24. Finish whichever part of Lab 24 you didn't finish
last class (Lab 24 is repeated below). Then sort the array of objects using
sort, described below. Upon returning to main, call print_pets to print the
sorted array. Finally, call a function printOnePet to print the first object in the array.
Write a function sort (you can use either sort) to sort the n objects in the pet array into ascending order by type of animal. Send the pet array and n, as parameters to the function. Use object assignment to do the
swapping, and remember to give temp
the data type vet_record.
Write a function printOnePet
to print ONE pet object. The function receives one object of type vet_record as a
parameter and prints all the data members of that one object. You do not need
to send n as a parameter. The formal
parameter in the function is NOT an array.
Here's
a review of Labs 23 and 24:
Class vet_record had three parts: an
object of class animal_info,
an object of class owner_info,
and a balance_due
field.
After creating the class definition, you wrote a declaration for an
array of objects of class vet_record. You
called it pet and it could hold info on 100 pets.
In Lab 24, you wrote two
functions, one to read values into the pet array of objects, and one to
print the pet array.
The print_pets
function receives two parameters, the array of objects of class vet_record, and n, the number of objects in
the array. Neither parameter is changed in the function. The function prints
the members of each object with messages in front of each, like this:
pet: Rover type of animal: dog age: 5
weight: 10.6
owner: Joe Smith phone: 718-555-5555
balance due: 5.60
The read_pets function receives two
parameters, the array of objects of class vet_record,
and n, the number of objects in the array. BOTH parameters are changed
in the function. The function reads in n and then reads n sets of
data values into the pets array. The function
reads from a file called lab24.dat which is available on your class page, in
the Labs section. In the file, the order of the data for type of animal and pet
name are reversed, so read type first: http://www.sci.brooklyn.cuny.edu/~jones/cisc1110/Labs/lab24.txt
In the main program, call read_pets and then call print_pets.
Now, write code in the main program to use the collection of data you've
just read in: